'''
原文件：E:\p1\gir1.jpg
目标文件：E:\p2\gir1.jpg

with 结合 open使用，可以帮助自动释放资源
'''
# with open(r'E:\p1\gir1.jpg','rb') as stream: #stream = open(r'E:\p1\gir1.jpg','rb')
#     container = stream.read() #读取文件内容
#
#     with open(r'E:\p2\gir1.jpg','wb') as wstream: #wstream = open(r'E:\p2\gir1.jpg','wb')
#         wstream.write(container) #写入文件内容
#
# print('复制完成')
'''
封装成函数
'''
import os
src_path = r'E:\p1\gir1.jpg'
target_path = r'E:\p2'
def copy(src,target):
    if os.path.isdir(src):
        filelist = os.listdir(src)
        for file in filelist:
            path = os.path.join(src,file)
            with open(path,'rb') as stream:
                container = stream.read()

                path1 = os.path.join(target,file)
                with open(path1,'wb') as wstream:
                    wstream.write(container)
        else:
            print('复制完成')

copy(src_path,target_path)

